package solutions.leetcode.easy;

import solutions.lib.BaseSolution;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/number-complement/">476. 数字的补数</a>
 */
public class Solution476 extends BaseSolution {

    public int findComplement(int num) {
        int rst = 0, floor = 0;
        while (num > 0) {
            int mod = num % 2;
            num /= 2;
            rst += Math.pow(2, floor++) * (1 - mod);
        }
        return rst;
    }

    public static void main(String[] args) {
        Solution476 solution = new Solution476();
        System.out.println(solution.findComplement(5));
    }
}